package com.yc.cloudvideo.sp_store.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yc.cloudvideo.entity.Store;
import com.yc.cloudvideo.entity.StoreUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.cloudvideo.entity.User;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LYYT
 * @since 2022-08-03
 */
public interface StoreUserMapper extends BaseMapper<StoreUser> {
    @Select("select * from store where cid in(select cid from store_user where uid=#{uid} and level in (1,2)) and exist=1")
    List<Store> selectStoresByUidToGuanLi(int uid);
    @Select("select * from user where uid in(select uid from store_user where cid=#{cid} and level=5)")
    List<User> selectUsersSQ(int cid);

    //查询申请列表
    @Select("select * from store_user where cid=#{cid} and level=5")
    @Results(value = {
            @Result(property = "uid",column = "uid",id = true),
            @Result(property = "user",column = "uid",
                    one=@One(select = "selectUserByUid"))
    })
    List<StoreUser> selectUsersSQ1(int cid);
    //查询仓库中的所有人员，按等级 1  ->  3 排序
    @Select("select * from store_user where cid=#{cid} and level<=3 order by level")
    @Results(value = {
            @Result(property = "uid",column = "uid",id = true),
            @Result(property = "user",column = "uid",
                    one=@One(select = "selectUserByUid"))
    })
    List<StoreUser> selectUsersInStoreByCid(int cid);


    //不查密码
    @Select("select uid,head,nick_name,sign,email,is_boy,age,reg_time,vip from user where uid=#{uid}")
    User selectUserByUid(int uid);

    int collectById(LambdaQueryWrapper<StoreUser> lqw);
}
